package ar.edu.utn.frba.dds.tp.tests.DateParser;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import junit.framework.Assert;

import org.joda.time.LocalDate;
import org.junit.Before;
import org.junit.Test;

import ar.edu.utn.frba.dds.tp.code.dateParser.CantParseException;
import ar.edu.utn.frba.dds.tp.code.dateParser.Formato;
import ar.edu.utn.frba.dds.tp.code.dateParser.FormatoFlexible;
import ar.edu.utn.frba.dds.tp.code.dateParser.FormatoSimple;
public class FormatoFlexibleTest {

	/*
	 * Tester: Lucas Giudice
	 */
	
	private FormatoFlexible formatoFlexible;
	private Date fecha;

	@Before
	public void setUp() {
		List<Formato> formatos = new ArrayList<Formato>();
		formatos.add(FormatoSimple.LATINOAMERICANO);
		formatos.add(new FormatoSimple("yyyy-MMMM-dd"));
	
		formatoFlexible = new FormatoFlexible(formatos);
		fecha = new LocalDate(2012,3,21).toDate();
		 
	}
	
	@Test
	public void parseaFechaOkTest() {
		Assert.assertEquals(fecha, formatoFlexible.parse("21/03/2012"));
	}
	
	@Test (expected = CantParseException.class) 
	public void parseaFechaFormatoFlexVacioFalloTest(){
		Assert.assertEquals(fecha, new FormatoFlexible(new ArrayList<Formato>()).parse("21/03/2012"));
	}
	
	@Test (expected = CantParseException.class) 
	public void parseaFechaErrorTest() {
		Assert.assertEquals(fecha, formatoFlexible.parse("2012-12-03"));
	}

}
